#ifndef __USER_WIFI_H
#define __USER_WIFI_H

#include "esp_wifi.h"
#include "esp_event.h"
#include "nvs_flash.h"
#include "esp_sntp.h"
#include "esp_http_client.h"
#include <stdio.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "cJSON.h"
#include "char_conversion.h"
#include "../../lvgl/src/extra/others/msg/lv_msg.h"
#include "../../refresh_data/include/refresh_data.h"
#include "lvgl_app.h"

/* Set the SSID and Password via project configuration, or can set directly here */
#define DEFAULT_SSID "Mi 10 Pro"
#define DEFAULT_PWD "1314521sb"

#if CONFIG_EXAMPLE_WIFI_ALL_CHANNEL_SCAN
#define DEFAULT_SCAN_METHOD WIFI_ALL_CHANNEL_SCAN
#elif CONFIG_EXAMPLE_WIFI_FAST_SCAN
#define DEFAULT_SCAN_METHOD WIFI_FAST_SCAN
#else
#define DEFAULT_SCAN_METHOD WIFI_FAST_SCAN
#endif /*CONFIG_EXAMPLE_SCAN_METHOD*/

#if CONFIG_EXAMPLE_WIFI_CONNECT_AP_BY_SIGNAL
#define DEFAULT_SORT_METHOD WIFI_CONNECT_AP_BY_SIGNAL
#elif CONFIG_EXAMPLE_WIFI_CONNECT_AP_BY_SECURITY
#define DEFAULT_SORT_METHOD WIFI_CONNECT_AP_BY_SECURITY
#else
#define DEFAULT_SORT_METHOD WIFI_CONNECT_AP_BY_SIGNAL
#endif /*CONFIG_EXAMPLE_SORT_METHOD*/

#if CONFIG_EXAMPLE_FAST_SCAN_THRESHOLD
#define DEFAULT_RSSI CONFIG_EXAMPLE_FAST_SCAN_MINIMUM_SIGNAL
#if CONFIG_EXAMPLE_FAST_SCAN_WEAKEST_AUTHMODE_OPEN
#define DEFAULT_AUTHMODE WIFI_AUTH_OPEN
#elif CONFIG_EXAMPLE_FAST_SCAN_WEAKEST_AUTHMODE_WEP
#define DEFAULT_AUTHMODE WIFI_AUTH_WEP
#elif CONFIG_EXAMPLE_FAST_SCAN_WEAKEST_AUTHMODE_WPA
#define DEFAULT_AUTHMODE WIFI_AUTH_WPA_PSK
#elif CONFIG_EXAMPLE_FAST_SCAN_WEAKEST_AUTHMODE_WPA2
#define DEFAULT_AUTHMODE WIFI_AUTH_WPA2_PSK
#else
#define DEFAULT_AUTHMODE WIFI_AUTH_OPEN
#endif
#else
#define DEFAULT_RSSI -127
#define DEFAULT_AUTHMODE WIFI_AUTH_OPEN
#endif /*CONFIG_EXAMPLE_FAST_SCAN_THRESHOLD*/

typedef struct _weather_data_t
{
    int weather_code;
    char weather_temp[5];
    char weather_date[5];
    char weather_weat[3];
    char weather_city[3];
    char weather_week[3];
} weather_data_t;
extern weather_data_t weather_data;

void init_NVS();
void event_handler(void *arg, esp_event_base_t event_base,
                   int32_t event_id, void *event_data);
void fast_scan(void);
void time_sync_notification_cb(struct timeval *tv);
void initialize_sntp(void);
void obtain_time(void);
bool parse_weather_json(char *analysis_buf, weather_data_t *data);
char *xinzhi_task(char *city_str);
char *parse_city_json(char *analysis_buf);
char *city_task(void);
esp_err_t _http_event_handler(esp_http_client_event_t *evt);

#endif // !
